package com.atguigu.spzx.manager.controller;


import com.atguigu.spzx.common.log.annotation.Log;
import com.atguigu.spzx.common.log.enums.BusinessType;
import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.dto.system.SysUserDto;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @ClassName: SysUserController
 * @Package: com.atguigu.spzx.manager.controller
 * @Description 用户管理
 * @Author 孤妤
 * @Date: 2023/12/5 9:44
 */
@RestController
@RequestMapping("/admin/system/sysUser")
@Tag(name = "用户管理")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;
    @GetMapping("/{pageNum}/{pageSize}")
    @Operation(summary = "分页查询以及根据关键字搜索分页")
    public Result<PageInfo<SysUser>> findByPage(@PathVariable Integer pageNum,
                                                @PathVariable Integer pageSize,
                                                SysUserDto sysUserDto){
        PageInfo<SysUser> pageInfo =  sysUserService.findByPage(pageNum,pageSize,sysUserDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/findById/{id}")
    @Operation(summary = "根据id查询用户信息")
    public Result findById(@PathVariable Long id){
        SysUser sysUser =  sysUserService.findById(id);
        return Result.build(sysUser,ResultCodeEnum.SUCCESS);
    }
    @PutMapping("/updateSysUser")
    @Operation(summary = "修改用户信息")
    public Result changeSysUser(@RequestBody SysUser sysUser){
        sysUserService.changeSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("修改成功");
    }
    @PostMapping("/save")
    @Operation(summary = "添加用户信息")
    @Log(title = "用户管理",businessType = BusinessType.INSERT)
    public Result addSysUser(@RequestBody SysUser sysUser){
        sysUserService.addSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("添加成功");
    }
    @DeleteMapping("/deleteById/{id}")
    @Operation(summary = "删除用户信息")
    @Log(title = "用户管理",businessType = BusinessType.DELETE,isSaveRequestData = false)
    public Result removeSysUser(@PathVariable Integer id){
        sysUserService.removeSysUser(id);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("删除成功");
    }
}
